package cn.stylefeng.guns.modular.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.IdjArtistAuthenticatioInfo;
import cn.stylefeng.guns.modular.entity.IdjAuthentication;
import cn.stylefeng.guns.modular.entity.responseVo.InfoVo;
import cn.stylefeng.guns.modular.entity.responseVo.TypeVo;
import cn.stylefeng.guns.modular.mapper.IdjAuthenticationMapper;
import cn.stylefeng.guns.modular.service.IIdjAuthenticationService;
import cn.stylefeng.guns.modular.util.json.JsonUtils;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * <p>
 * 实名认证表 服务实现类
 * </p>
 *
 * @author TANGWJ
 * @since 2020-07-30
 */
@Service
public class IdjAuthenticationServiceImpl extends ServiceImpl<IdjAuthenticationMapper, IdjAuthentication> implements IIdjAuthenticationService {

	@Autowired
	private IdjAuthenticationMapper mapper;
	
	@Override
	public LayuiPageInfo getList(Page<IdjAuthentication> page, String keyword, String beginTime, String endTime,
			String yes, String no, Integer idType) {
		Page<Map<String,Object>> list = mapper.getList(page, keyword, beginTime, endTime, yes, no, idType);
		return LayuiPageFactory.createPageInfo(list);
	}

	@Override
	public ModelAndView edit(Long realAuthenticationId) {
		IdjAuthentication authentication = mapper.selectByKeyId(realAuthenticationId);
		if(authentication != null){
			if(ToolUtil.isNotEmpty(authentication.getStatus())){
				if(authentication.getStatus() == 1){
					authentication.setReasonTypeName("已通过");
				}else{
					authentication.setReasonTypeName("已拒绝");;	
				}
			}
			if(ToolUtil.isNotEmpty(authentication.getServiceType())){
				if(authentication.getServiceType().equals("1")){
					authentication.setServiceType("嘉宾演出");
				}else{
					authentication.setServiceType("驻场演出");
				}
			}
			if(ToolUtil.isNotEmpty(authentication.getIdType())){
				if(authentication.getIdType()==1){
					authentication.setIdTypeName("居民身份证");
				}else if(authentication.getIdType()==2){
					authentication.setIdTypeName("护照");
				}else if(authentication.getIdType()==3){
					authentication.setIdTypeName("回乡证");
				}else if(authentication.getIdType()==4){
					authentication.setIdTypeName("台胞证");
				}
			}
			if(ToolUtil.isNotEmpty(authentication.getCity())){
				authentication.setCityName(authentication.getCity());
			}	
			if(ToolUtil.isNotEmpty(authentication.getRegion())){
				if(ToolUtil.isNotEmpty(authentication.getRegion()) && ToolUtil.isNotEmpty(authentication.getCityName())){
					authentication.setCityName(authentication.getCityName()+'-'+authentication.getRegion());
				}else{
					authentication.setCityName(authentication.getRegion());
				}
			}	
			if(ToolUtil.isNotEmpty(authentication.getImportantEvent())){
				authentication.setVo(JsonUtils.toObject(authentication.getImportantEvent(), InfoVo.class));
			}
			if(authentication.getGender() == 1){
				authentication.setGenderName("男");
			}else if(authentication.getGender() == 2){
				authentication.setGenderName("女");
			}else{
				authentication.setGenderName("未知");
			}
			List<String> list = new ArrayList<String>();
			if(ToolUtil.isNotEmpty(authentication.getAuditRejectionImg())){
				String[] split = authentication.getAuditRejectionImg().split(",");
				for (int i = 0; i < split.length; i++) {
					list.add(split[i]);
				}
				authentication.setImgList(list);
			}
		}
		ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("authentication", authentication);
        return modelAndView;
	}

	@Override
	public int setIsAudit(IdjAuthentication cation) {
		return mapper.setIsAudit(cation);
	}
}
